package io.task.cc.network.maintain;

import io.task.cc.network.ChannelContext;
import io.task.cc.network.Config;
import io.task.cc.network.spi.client.ClientConfig;


public class MaintainUtils {

    /**
     * 彻底删除，不再维护
     */
    public static void remove(ChannelContext channelContext) {
        Config config = channelContext.config;
        if (!config.isServer()) {
            ClientConfig clientConfig = (ClientConfig) config;
            clientConfig.closeds.remove(channelContext);
            clientConfig.connecteds.remove(channelContext);
        }

        config.connections.remove(channelContext);
        config.ips.unbind(channelContext);
        config.ids.unbind(channelContext);

        close(channelContext);
    }


    public static void close(ChannelContext channelContext) {
        Config config = channelContext.config;
        config.users.unbind(channelContext);
        config.tokens.unbind(channelContext);
        config.groups.unbind(channelContext);

        config.bsIds.unbind(channelContext);

    }


}
